package com.wes.dsptest.audioalarm;

import android.app.AlertDialog;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.view.WindowManager;
import android.widget.Toast;

public class AlarmReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle("闹钟");
        builder.setMessage("时间到了！");
        builder.setPositiveButton("确定", null);
        AlertDialog dialog = builder.create();
        if (Build.VERSION.SDK_INT >= 23)
        {
            dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
        }else
        {
            dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        }

        dialog.show();

        Toast.makeText(context, "时间到了", Toast.LENGTH_SHORT).show();
        sendBroad(context);

    }

    private void sendBroad(Context context){
        Intent intent = new Intent();
        intent.putExtra("cmd", "alarm");
        intent.setAction("com.wes.dsptest");
        context.sendBroadcast(intent);
    }
}
